/* buildRemove */
define(['angular'], function () {
/* end-buildRemove */
    'use strict';

    var bootstrapDialog = angular
        .module('app.core')
        .factory('bootstrap.dialog', ['$modal', '$templateCache',modalDialog]);

    /* @ngInject */
    function modalDialog($modal, $templateCache) {
        var service = {
            deleteDialog: deleteDialog,
            confirmationDialog: confirmationDialog
        };

        $templateCache.put('modalDialog.tpl.html',
                '<div>' +
                '    <div class="modal-header">' +
                '        <button type="button" class="close" data-dismiss="modal" ' +
                '            aria-hidden="true" data-ng-click="cancel()">&times;</button>' +
                '        <h3>{{title}}</h3>' +
                '    </div>' +
                '    <div class="modal-body">' +
                '        <p>{{message}}</p>' +
                '    </div>' +
                '    <div class="modal-footer">' +
                '        <button class="btn btn-primary" data-ng-click="ok()">{{okText}}</button>' +
                '        <button class="btn btn-info" data-ng-click="cancel()">{{cancelText}}</button>' +
                '    </div>' +
                '</div>');

        return service;

        function deleteDialog(itemName) {
            var title = 'Confirm Delete';
            itemName = itemName || 'item';
            var msg = 'Delete ' + itemName + '?';

            return confirmationDialog(title, msg);
        }

        function confirmationDialog(title, msg, okText, cancelText) {

            var modalOptions = {
                templateUrl: 'modalDialog.tpl.html',
                controller: ModalInstance,
                keyboard: true,
                resolve: {
                    options: function () {
                        return {
                            title: title,
                            message: msg,
                            okText: okText,
                            cancelText: cancelText
                        };
                    }
                }
            };

            return $modal.open(modalOptions).result;
        }
    }

    ModalInstance.$inject = ['$scope', '$modalInstance', 'options'];

    /* @ngInject */
    function ModalInstance($scope, $modalInstance, options) {
        $scope.title = options.title || 'Title';
        $scope.message = options.message || '';
        $scope.okText = options.okText || 'OK';
        $scope.cancelText = options.cancelText || 'Cancel';
        $scope.ok = function () {
            $modalInstance.close('ok');
        };
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    }

    /* buildRemove */return /* end-buildRemove */bootstrapDialog;
/* buildRemove */
});
/* end-buildRemove */